package main.java.easy;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author: 郑国荣
 * @Date: 2023-07-11-9:03
 * @Description: 剔除重复元素
 */
class NumsRemove {
    //移除重复数字
    public int removeDuplicates(int[] nums) {
        if(nums.length <2) return nums.length;
        int j=0;
        for(int i = 0;i<nums.length;i++){
            if(nums[j] != nums[i]) nums[++j]=nums[i];
        }
        return ++j;
    }

    //寻找重复数字
    public static List<Integer> findRepeatNumber(int[] nums) {
        Set<Integer> mp = new HashSet<>();
        ArrayList<Integer> integers = new ArrayList<>();
        for(int num : nums){
            if(mp.contains(num)) integers.add(num);
            else mp.add(num);
        }
        return integers;
    }

    public static void main(String[] args) {
        int[] a ={1,1,2,5,7,5};
        System.out.println(findRepeatNumber(a));
    }
}
